package com.school.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.school.dao.HljtClassDao;
import com.school.dao.HljtStudentDao;
import com.school.entity.HljtOnduty;
import com.school.entity.HljtStudent;
import com.school.service.HljtStudentService;
@Service
public class HljtStudentServiceImpl implements HljtStudentService{
	
	@Autowired
	private HljtStudentDao hljtStudentDao;
	@Autowired
	private HljtClassDao hljtClassDao;
	


	@Override
	@Transactional(readOnly=true)
	public List<HljtStudent> studentWorks(HljtStudent hljtStudent) {
		List<HljtStudent> temp = hljtStudentDao.studentWorks(hljtStudent);
		Map<Integer, Object> map = new HashMap<>();
		List<HljtStudent> re = new ArrayList<>();
		if(null != temp && temp.size()>0) {
			for (HljtStudent te : temp) {
				if(!map.containsKey(te.getId())) {
					map.put(te.getId(), 1);
					re.add(te);
				}
			}
		}
		return re;
	}
	
	@Override
	@Transactional(readOnly=true)
	public List<HljtOnduty> studentDuty(HljtOnduty hljtOnduty) {
		List<HljtOnduty> temp = new ArrayList<>();
		List<HljtOnduty> list = hljtStudentDao.studentDuty(hljtOnduty);
		for (HljtOnduty hljtOnduty2 : list) {
			if(hljtOnduty2.getWeek().equals("星期一")) {
				HljtOnduty h = new HljtOnduty();
				h.setWeek(hljtOnduty2.getWeek());
				
			}else if(hljtOnduty2.getWeek().equals("星期二")){
				
			}else if(hljtOnduty2.getWeek().equals("星期三")){
				
			}else if(hljtOnduty2.getWeek().equals("星期四")){
				
			}else if(hljtOnduty2.getWeek().equals("星期五")){
				
			}else if(hljtOnduty2.getWeek().equals("星期六")){
				
			}else if(hljtOnduty2.getWeek().equals("星期日")){
				
			}
			
		}
		return temp;
	}

	@Override
	@Transactional
	public Integer addStudent(List<HljtStudent> hljtStudent) {
		
		return hljtStudentDao.addStudent(hljtStudent) ;
	}

	@Override
	public Map<String , Object> selectStudentByClassId(HljtStudent hljtStudent) {
		 Map<String , Object> map = new HashMap<>();
		if(null!=hljtStudent) {
			if(hljtStudent.getClassid()==-1) {
				map.put("allClass", hljtClassDao.findClasslistOrCalssId(null));
			}else {
				map.put("count", hljtStudentDao.selectStudentByClassIdCount(hljtStudent));
				map.put("allClass", hljtClassDao.findClasslistOrCalssId(hljtStudent.getClassid()));
				map.put("allStudent", hljtStudentDao.selectStudentByClassId(hljtStudent));
			}
		}
		
		return map;
	}

	@Override
	public Integer updateStudentByClassId(List<HljtStudent> hljtStudent) {
		// TODO Auto-generated method stub
		return hljtStudentDao.updateStudentByClassId(hljtStudent);
	}

	@Override
	public Integer updateStudentInfoByClassId(HljtStudent hljtStudent) {
		// TODO Auto-generated method stub
		return hljtStudentDao.updateStudentInfoByClassId(hljtStudent);
	}

	@Override
	public HljtStudent findStudent(Integer id) {
		// TODO Auto-generated method stub
		return hljtStudentDao.findStudent(id);
	}

	@Override
	public HljtStudent selectStudent(Integer classid, String studentName) {
		// TODO Auto-generated method stub
		return hljtStudentDao.selectStudent(classid, studentName);
	}

	@Override
	public List<HljtStudent> findStudentName(String name, Integer pageSize, Integer pageIndex) {
		// TODO Auto-generated method stub
		return hljtStudentDao.findStudentName(name, pageSize, pageIndex);
	}

	@Override
	public Integer updateStudent(HljtStudent hljtStudent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer updateStudents(HljtStudent hljtStudent) {
		// TODO Auto-generated method stub
		return hljtStudentDao.updateStudents(hljtStudent);
	}

	@Override
	public List<HljtStudent> findStudentAll() {
		// TODO Auto-generated method stub
		return hljtStudentDao.findStudentAll();
	}


}




